﻿using Microsoft.Extensions.DependencyInjection;
using StartsEAS_API.BLL.Interfaces.IClasssB;
using StartsEAS_API.DAL.ClassD;
using StartsEAS_API.Model;
using StartsEAS_API.Model.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StartsEAS_API.BLL.ClassB
{
    public class ClassBLL : IClassBLL
    {
        private readonly StarsEASContext _context;
        public ClassDAL _classDal;
        public ClassBLL(IServiceScopeFactory context)
        {
            _context = context.CreateScope().ServiceProvider.GetRequiredService<StarsEASContext>();
            _classDal = new(_context);
        }

        public ResultUtils AddClasses(string token, Class classes)
        {
            int result = _classDal.AddClasses(token, classes);
            if(result == -1) return new ResultUtils() { code = 500, message = "您未进行改变或操作异常" };
            return new ResultUtils() { code = 200, message = "操作成功" };
        }

        public ResultUtils GetAllClasses()
        {
            IEnumerable<Class> classes = _classDal.GetAllClasses();
            if(classes ==null) return new ResultUtils() { code = 500, message = "数据为空" };
            return new ResultUtils() { code = 200, message = classes };
        }

        public ResultUtils GetAllClassesByProfessionalId(int ProfessionalId)
        {
            IEnumerable<Class> classes = _classDal.GetAllClassesByProfessionalId(ProfessionalId);
            if (classes == null) return new ResultUtils { code = 500, message = "根据专业编号未查询到班级信息" };
            return new ResultUtils() { code = 200, message = classes };
        }

        public ResultUtils GetClassesByClassId(string ClassId)
        {
            var classes = _classDal.GetClassesByClassId(ClassId);
            if (classes == null) return new ResultUtils() { code = 500, message = "班级为空" };
            return new ResultUtils() { code = 200, message = classes };
        }

        public ResultUtils GetClassesByToken(string token)
        {
            var classes = _classDal.GetClassesByToken(token);
            if (classes == null) return new ResultUtils() { code = 500, message = "您的Token错误或班级为空" };
            return new ResultUtils() { code = 200, message = classes };
        }

        public ResultUtils UpdateClasses(string token, Class data)
        {
            int result = _classDal.UpdateClasses(token, data);
            if (result == -1) return new ResultUtils() { code = 500, message = "您未进行改变或操作异常" };
            return new ResultUtils() { code = 200, message = "操作成功" };
        }
    }
}
